// pages/searchWord/searchWord.js
Page({

	/**
	 * 页面的初始数据
	 */
	data: {
		keyWord: '',
		historysearchlist: []
	},
	
	/**
	 * 生命周期函数--监听页面加载
	 */
	onLoad: function (options) {
		let ketWords = options.keyword;
		this.setData({
			'keyWord': ketWords
		})
	},
	confirm(e) {
    console.log(e)
    if (e.detail.value.trim() == '') {
      return false
    }
    var isseem = false
    for (var key of this.data.historysearchlist) {
      if (key === e.detail.value) {
        isseem = true
        break;
      }
    }
    if (!isseem) {
      this.data.historysearchlist.unshift(e.detail.value)
      var hislist = this.data.historysearchlist.slice(0, 10)
      wx.setStorageSync('historysearchlist', hislist)
      this.setData({
        historysearchlist: hislist
      })
    }
    wx.navigateTo({
      url: '/pages/search/search?keyword=' + e.detail.value.trim()
    })

	},
	// 
	clearbind() {
    this.setData({
      historysearchlist: []
    })
    wx.removeStorageSync('historysearchlist')
	},
	
	searchItem(e) {
    console.log(e)
    var keyword = e.currentTarget.dataset.keyword
    wx.navigateTo({
      url: '/pages/search/search?keyword=' + keyword.trim()
    })
  },
	/**
	 * 生命周期函数--监听页面初次渲染完成
	 */
	onReady: function () {

	},

	/**
	 * 生命周期函数--监听页面显示
	 */
	onShow: function () {
    var historysearchlist = wx.getStorageSync('historysearchlist')
    if (historysearchlist) {
      this.setData({
        historysearchlist
      })
    }
  },

	/**
	 * 生命周期函数--监听页面隐藏
	 */
	onHide: function () {

	},

	/**
	 * 生命周期函数--监听页面卸载
	 */
	onUnload: function () {

	},

	/**
	 * 页面相关事件处理函数--监听用户下拉动作
	 */
	onPullDownRefresh: function () {

	},

	/**
	 * 页面上拉触底事件的处理函数
	 */
	onReachBottom: function () {

	},

	/**
	 * 用户点击右上角分享
	 */
	onShareAppMessage: function () {

	}
})